import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class Main  extends Thread implements ActionListener  {


    public  String[] fileRead() throws Exception{
        File file = new File("D:\\01.txt");
        FileReader reader = new FileReader(file);
        BufferedReader bufferedReader = new BufferedReader(reader);
        StringBuffer stringBuffer = new StringBuffer();
        String s = "";
        while ((s = bufferedReader.readLine())!=null){
            stringBuffer.append(s+"\n");

        }
        bufferedReader.close();
        String str[] = stringBuffer.toString().split("\n");
        return str;

    }
    String[] s;

    {
        try {
            s = fileRead();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    JFrame frame=new JFrame("点名使用");
    JButton btn=new JButton("停止");
    JTextField tf=new JTextField();
    public Main(){
        frame.setLayout(null);
        frame.setBounds(300, 400, 300, 350);
        tf.setBounds(100, 40, 120, 30);
        tf.setFont(new Font("Monospaced", 23, 30));
        btn.setBounds(80, 120, 150, 100);
        frame.add(btn);
        frame.add(tf);
        frame.setVisible(true);
        btn.addActionListener(this);
       frame.addWindowListener(new WindowAdapter() {
           @Override
           public void windowClosing(WindowEvent e) {
               System.exit(0);
           }
       });
    }
    public void run(){
        for(int i=1;i<=6;i++){

            tf.setText(s[i-1]);
            try {
                sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(i==6)i=1;
        }
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==btn){
            if(btn.getText().equals("开始")){
                this.resume();
                btn.setText("停止");
            }
            else if(btn.getText().equals("停止")){
                //this.stop();
                this.suspend();
                btn.setText("开始");
            }
        }
    }


    public static void main(String[] args)   {

        Main m=new Main();
        m.start();
    }


}
